package net.xconcepts.stockdata.model;

import java.util.List;
import java.util.Map;

import net.xconcepts.stockdata.model.analysis.symbol.Symbol;
import net.xconcepts.stockdata.model.tick.SymbolTick;
import net.xconcepts.stockdata.model.tick.TickDataField;

/**
 * Contains the logic to ensure sell orders can only be issued on held stocks
 * @author Steven
 *
 */
public abstract class Prioritizer {
	
	private final Portfolio mPortfolio;
	//have own filters?
	
	public Prioritizer(Portfolio portfolio) {
		mPortfolio = portfolio;
	}
	
	public abstract List<TraderAction> processMarketTick(Map<Symbol, SymbolTick> buyTicks,
			Map<Symbol, SymbolTick> sellTicks);
	
	public final void addRule() {
		//TODO
	}
	
	/**
	 * Creates action at close price
	 * @param symbol
	 * @param amount
	 * @param tick
	 * @return
	 */
	protected final TraderAction createBuyAction(Symbol symbol, int amount, SymbolTick tick) {
		TraderAction action = new TraderAction(TraderAction.Action.BUY,
				symbol, amount, tick.getData(TickDataField.Close));
		return action;
	}
	
	/**
	 * Creates action at close price
	 * @param symbol
	 * @param amount
	 * @param tick
	 * @return
	 */
	protected final TraderAction createSellAction(Symbol symbol, int amount, SymbolTick tick) {
		TraderAction action = new TraderAction(TraderAction.Action.SELL,
				symbol, amount, tick.getData(TickDataField.Close));
		return action;
	}
	
	public final Portfolio getPortfolio() {
		return mPortfolio;
	}
}
